/**************************************************************
  > File Name: 13.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年01月28日 星期五 13时21分51秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int romanToInt(char * s)
{
	const int vaule[] = {1000,500,100,50,10,5,1,900,400,90,40,9,4};
	const char *symbols[] = {"M","D","C","L","X","V","I","CM","CD","XC","XL","IX","IV"};
	char *p = s;
	int i, j, flag;
	int sum = 0;
	int cur = 0;
	
	while (*p)
	{
		for (i = 0; i < 13; i++)
		{
			if (strncmp(p, symbols[i], strlen(symbols[i])) == 0)
			{
				cur = vaule[i];
				flag = strlen(symbols[i]);
			}
		}
		sum += cur;
		p += flag;
	}
	return sum;
}

int main(int argc,char **argv)
{
	char *s = "LVIIIV";
	int ret = 0;

	ret = romanToInt(s);
	printf("%d\n",ret);

    exit(0);
}
